home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: File.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1993 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes. */
-
- /* This file is where you place various definitions and constant values for
- ** DTS.Lib..framework's use. You will also add some code within the two
- ** functions to handle the various document types. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.defs.h" /* Get various application definitions. */
- #include "App.protos.h" /* Get the prototypes for application. */
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
-
- /* In this file, we first set some global values. This allows the application and
- ** DTS.Lib..framework to "know" what is expected for certain default actions. */
-
-
- short gTypeListLen = 1;
- SFTypeList gTypeList = {kDocFileType};
- /* Here we declare the various document types that Wannabe can support.
- ** These definitions are to inform DTS.Lib..framework what documents can be opened. */
-
-
-
- /* Some DTS.Lib..framework gTypeList usage notes:
- **
- ** 1) Framework uses gTypeList[0] for the default document, if there is one.
- ** 2) NewDocument() is passed a document type. It searches gTypeList for a match.
- ** The index at which the match is found (+1) is used as the string number in the
- ** STR# resource rDefaultTitles. If there aren't enough strings in the STR#
- ** resource, then the last string is used.
- ** 3) The gTypeList is used for the StandardFile calls to determine which files
- ** can be selected. */
-
-
-
- #ifdef powerc
- #pragma options align=mac68k
- #endif
- typedef struct DocFileTypeRec { /* This is used only to determine the size of the document */
- FileStateRec fileState; /* structure. We can't just add the three components, as */
- ConnectRec connect; /* it is unclear how much padding any particular compiler */
- TheDoc doc; /* will place on the end of each. */
- } DocFileTypeRec; /* The only place that this should be used is in this file. */
- #ifdef powerc
- #pragma options align=reset
- #endif
-
-
-
- /* Below are the TreeObj procedure pointers for the various kinds of objects we use in this
- ** application. The first 16 are reserved for the framework. Our application-specific
- ** objects start at 16. */
-
- TreeObjProcPtr gTreeObjMethods[kNumTreeObjs] = {nil,
- /* 1 */ TRootObj,
- /* 2 */ TUndoObj,
- /* 3 */ TUndoTaskObj,
- /* 4 */ TUndoPartObj,
- /* 5 */ nil,
- /* 6 */ nil,
- /* 7 */ nil,
- /* 8 */ nil,
- /* 9 */ nil,
- /* 10 */ nil,
- /* 11 */ nil,
- /* 12 */ nil,
- /* 13 */ nil,
- /* 14 */ nil,
- /* 15 */ nil};
- /* 16 Start of app-specific procs. */
-
-
-
- /* The framework needs to know the minimum object sizes. This table is used by the
- ** framework to make sure that the object is created at least minimally. */
-
- long gMinTreeObjSize[kNumTreeObjs] = {0,
- /* 1 */ sizeof(RootObj),
- /* 2 */ sizeof(UndoObj),
- /* 3 */ sizeof(UndoTaskObj),
- /* 4 */ sizeof(UndoPartObj),
- /* 5 */ 0,
- /* 6 */ 0,
- /* 7 */ 0,
- /* 8 */ 0,
- /* 9 */ 0,
- /* 10 */ 0,
- /* 11 */ 0,
- /* 12 */ 0,
- /* 13 */ 0,
- /* 14 */ 0,
- /* 15 */ 0};
- /* 16 Start of app-specific sizes. */
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* •• Called by DTS.Lib..framework. •• */
-
- /* Do any additional document initialization here. All fields not specifically set
- ** are already initialized to 0. */
-
- #pragma segment File
- OSErr InitDocument(FileRecHndl frHndl)
- {
- OSErr err;
-
- err = noErr;
-
- switch ((*frHndl)->fileState.sfType) {
- case kDocFileType:
- case 'DTST':
- (*frHndl)->fileState.sfType = kDocFileType;
- err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
- if (!err) {
- /* Any additional document initialization could go here. */
- }
- break;
- #if VH_VERSION
- case kViewHierFileType:
- return(VHInitDocument(frHndl));
- break;
- #endif
- default:
- err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
- if (!err) {
- (*frHndl)->fileState.readDocumentProc = nil;
- (*frHndl)->fileState.writeDocumentProc = nil;
- }
- break;
- }
-
- return(err);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• Called by DTS.Lib..framework. •• */
-
- /* Return the initial size of the primary document handle, based on the OSType. */
-
- #pragma segment File
- long InitDocumentSize(OSType sftype)
- {
- switch (sftype) {
- case kDocFileType:
- case 'DTST':
- return(sizeof(DocFileTypeRec));
- break;
- #if VH_VERSION
- case kViewHierFileType:
- return(VHFileTypeSize());
- break;
- #endif
- default:
- return(sizeof(DocFileTypeRec));
- break;
- }
- }
-
-
-
-